﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IniParser;

namespace Software_Installer
{
    public partial class MainUI : Form
    {
        private string _Title;
        //private Installer.InstallerAPI _InstallerAPI;
        //private List<string> _ToInstall;

        public MainUI()
        {
            InitializeComponent();
            //_ToInstall = new List<string>();
            //_InstallerAPI = new Installer.InstallerAPI();

            _Title = "Cairns SHS Student Software Installer";
            lbl_title.Text = _Title;
            this.Text = _Title;
            LoadTabContol();

        }

        private void LoadTabContol()
        {
            foreach (SectionData section in InstallerInterFace.Instance.GetSections())
            {
                Tab_Control.TabPages.Add(section.SectionName);
                addcontrols(section);
            }
        }

        private void addcontrols(SectionData Section)
        {
            foreach (TabPage tabPage in Tab_Control.TabPages)
            {
                tabPage.Name = tabPage.Text;
                ListBox tempbox = new ListBox();
                tempbox.Name = "LB" + tabPage.Name;
                tempbox.Height = Tab_Control.Size.Height;
                tempbox.Width = Tab_Control.Size.Width; ;
                foreach (KeyData KD in Section.Keys)
                {
                    tempbox.Items.Add(KD.KeyName);
                }
                tabPage.Controls.Add(tempbox);
            }
        }

        private void btn_add_Click(object sender, EventArgs e)
        {

            ListBox templist = (ListBox)Tab_Control.SelectedTab.Controls["LB" + Tab_Control.SelectedTab.Name];
            try
            {
                string toadd = Tab_Control.SelectedTab.Name + "#" + templist.SelectedItem;
                LB_toinstall.Items.Add(toadd);
                InstallerInterFace.Instance.AddToInstallList(toadd);

                //_ToInstall.Add(toadd);
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err);
            }
        }

        private void btn_go_Click(object sender, EventArgs e)
        {
            CurrentAction Currentaction = new CurrentAction();
            Currentaction.Show();

            
        }

        private void InstallThread()
        {

        }
    }
}
